package com.rockcent.wechat.payment;

import com.thoughtworks.xstream.XStream;
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by oyhk on 16/5/29.
 */
public class RXStreamTransformer  {

    protected static final Map<Class, XStream> CLASS_2_XSTREAM_INSTANCE = configXStreamInstance();

    /**
     * pojo -> xml
     *
     * @param clazz
     * @param object
     * @return
     */
    public static <T> String toXml(Class<T> clazz, T object) {
        return CLASS_2_XSTREAM_INSTANCE.get(clazz).toXML(object).replaceAll("__","_");
    }

    private static Map<Class, XStream> configXStreamInstance() {
        Map<Class, XStream> map = new HashMap<Class, XStream>();
        XStream xstream = XStreamInitializer.getInstance();
        xstream.processAnnotations(WxMpPayCallBackReturnResult.class);
        map.put(WxMpPayCallBackReturnResult.class, xstream);
        return map;
    }
}
